<!DOCTYPE html>
<!-- 会员后台页面 -->
<html>
<head>
  <meta charset="utf-8">
  <title>公司管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 
  <link rel="stylesheet" href="../../res/css/wholesale/font.css">
  <link rel="stylesheet" href="../../res/css/wholesale/xadmin.css">
  <link rel="stylesheet" href="../../res/layui/css/layui.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript" src="../../res/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../../res/js/wholesale/xadmin.js"></script>
</head>
<body>
       <div class="demoTable" style="margin-top: 10px;">
       
 	 <div id="time" class="demoTable">

	  <div class="layui-inline">
	    <input type="text" name="companyName" id="companyName" placeholder="请输入公司名称" autocomplete="off" class="layui-input">
	  </div>
  		<button class="layui-btn" data-type="reload" id="sous">搜索</button>
      <xblock>
        <button class="layui-btn" id="demoinsert"><i class="layui-icon"></i>添加</button>
      </xblock>
      
     
<table class="layui-table" lay-data="{url:'../../listenCompany/findAll.action', page:true, id:'idTest'}" lay-filter="demo">
  <thead>
    <tr>
      <th lay-data="{field:'companyId', sort: true, align:'center',style='display:none'}">公司ID</th>
      <th lay-data="{field:'companyName', align:'center'}">公司名称</th>
      <th lay-data="{field:'companyAddress',align:'center'}">公司地址</th>
      <th lay-data="{field:'companyType', align:'center',templet:'#auditingStatusType'}">公司类型</th>
      <th lay-data="{field:'openTimeVo', align:'center'}">操作时间</th>
      <th lay-data="{field: 'sort' align:'center'}">操作人</th>
      <th lay-data="{field: 'oper' align:'center'}">排序</th>
      <th lay-data="{field:  'rigth', align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>
 </div>
 </div>
<script type="text/html" id="barDemo">
  {{ subMitType(d) }}
</script>
<script type="text/html" id="auditingStatusType">
     {{# if(d.companyType == 1) { }}
     <div>分公司</div>
 	 {{# } else if(d.companyType == 0){ }}
     <div>总公司</div>
{{# }}}
 </script> 
  <script type="text/javascript">
 	function subMitType(d){
 		var  Subhtml = "";
 		if(d.companyId==1){
 			Subhtml='<a class="layui-btn layui-btn-xs layui-btn-disabled" >修改</a><a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" >删除</a>';
 		}else {
 			Subhtml='<a class="layui-btn layui-btn-xs " lay-event="edit">修改</a><a class="layui-btn layui-btn-xs " lay-event="auditDetail">审核记录</a><a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="del">删除</a>';
 		}
 		return Subhtml;
 	}
 </script>  
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use('table', function(){
  var table = layui.table;
  //监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
  });
  //监听工具条
  table.on('tool(demo)', function(obj){
    var da = obj.data;
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
    	var url="../../listenCompany/delete.action"; 
    	var data={"companyId":da.companyId};
        $.post(url,data,function(mes){
          layer.msg(mes.msg);
          obj.del();
        },"json");
      });
    } else if(obj.event === 'edit'){
    	layer.open({
    		type:2
    		,title:'修改'
    		,area: ['450px', '560px']
    	  ,content: ['ListenCompanyadd.html', 'no']
    	,success:function(layero, index){
    		var body = layer.getChildFrame('body', index);
	    	 var iframe = window[layero.find('iframe')[0]['name']]; 
	    	 var url="../../listenCompany/findById.action";
	    	 var data={"companyId":da.companyId};
	    	 

	    	 $.ajax({
	    		 async:false,
	    		 url:url,
	    		 data:data,
	    		 dataType:"json",
	    		 success:function(mes){
	    				 iframe.$("#companyId").val(mes.companyId); 
			    		 iframe.$("#companyName").val(mes.companyName);
			    		 iframe.$("#companyAddress").val(mes.companyAddress);
			    		 iframe.$("#companyType").val(mes.companyType);
			    		 iframe.$("#isva").val(mes.isva);
			    		 alert(mes.openTimeVo);
			    		 iframe.$("#openTimeVo").val(mes.openTimeVo); 
			    		 iframe.load();
	    		 }
	    	 });
	    	 
 
	    	 
    	}
    	//完成操作后自动刷新页面 
    	,
    	});
    	
    	}else if(obj.event === 'auditDetail'){
        	layer.open({
            	  title: "审核记录",
          		  type: 2, //设置为iframe
          		  shift:1,//弹出框动画效果
          		  area: ['66%', '55%'],
          		 content: ['../../pages/companyLeague/leagueAuditDetail.html?id='+da.companyId, 'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
          		 
          	  }); 
          }
    });
  
 
  var $ = layui.$, active = {
		    reload: function(){
		      var demoReload = $('#demoReload');
		      var companyName=$('#companyName');
		      //执行重载
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		      ,where: {
		        key: {
		        	companyName: companyName.val()
		        }
		      }
		   });
		}
  
	};
  	//关闭按钮 
  $('.demoTable .layui-btn').on('click', function(){
	  var type = $(this).data('type');
	  active[type] ? active[type].call(this) : '';
});
//增加 
$('#demoinsert').on('click', function(){
	  layer.open({
	        type: 2 //此处以iframe举例
	        ,title: '增加'
	        ,area: ['450px', '270px']
	        ,content: ['../listenCompany/ListenCompanyadd.html' , 'no']
			 
	  });
});
});
</script>
</body>
</html>